package com.atguigu.yygh.hosp.controller;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(description = "医院接口")
@RestController
@RequestMapping("/admin/hosp/hospital")
//@CrossOrigin
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    //根据医院id获取医院详细信息
    @GetMapping("/detail/{id}")
    public R getHospitalDataById(@PathVariable(value = "id") String id) {
        Map<String, Object> map = hospitalService.getHospitalDataById(id);
        return R.ok().data("hospital", map);
    }


    //更新医院上下线状态
    @PutMapping("/updateStatus/{id}/{status}")
    public R updateStatus(@PathVariable("id") String id,
                          @PathVariable("status") Integer status) {
        hospitalService.updateStatus(id, status);
        return R.ok();
    }

    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public R getHospitalPage(@PathVariable(value = "page") Integer page,
                             @PathVariable(value = "limit") Integer limit,
                             HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> pages = hospitalService.selectPage(page, limit, hospitalQueryVo);
        return R.ok().data("pages", pages);
    }
}
